import Vue from 'vue'
import App from './App'
import axios         from 'axios';
import echarts from 'echarts'
import AMap from 'vue-amap';
//播放器相关
import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.prototype.$axios= axios;
Vue.prototype.$echarts = echarts;
import router from './router'
import Vuex from "vuex"			//之后配置引入vuex
import './assets/font-awesome/css/font-awesome.min.css';
import './assets/css/reset.css';
import './assets/css/common.scss';
 

import ElementUI from 'element-ui'
import '../src/assets/element/index.css'
import store from './store/index.js'			//之后配置引入vuex
import Debounce from '@/utils/shank'
import vueEsign from 'vue-esign'
import  '@/utils/directives'
const service = axios.create({
    // baseURL        : baseUrl,
    timeout        : 60000 * 60,   //响应时长可根据业务需求自行设置
    responseType   : "json",
    withCredentials: false,
    headers        : {
        'Content-Type': 'application/json;charset=UTF-8',
    }
})
Vue.component('Debounce',Debounce)

// import '../src/style/index.css'
//  请求拦截器
service.interceptors.request.use(
    config=>{
        if (store.state.token) { // 判断是否存在token，如果存在的话，则每个http header都加上token
            config.headers.Authorization = `token ${store.state.token}`;
           }
           return config
    },
    err=>{
        return promise.reject(error)
    }
    // function(config){
    //     return config
    // },
    // function (error) {
    //     return Promise.reject(error)
    //   }
),
// 响应拦截器
service.interceptors.response.use(
    // const data=response.data.data
    response => {
 if(response.data.code==200){
    const data = response.data
    return Promise.resolve(response)
 }else{
switch(data.code){
    case 401:
    Notification({
        message : "token失效",
        type    : 'error',
        duration: 3 * 1000
    })
    break;
    case 500:
        Notification({
            message : data.msg,
            type    : 'error',
            duration: 3 * 1000
        })
    break;
    case 600:
        Notification({
            message : data.msg,
            dangerouslyUseHTMLString: true,
            type    : 'error',
            duration: 3 * 1000
        })
    break;
 }}
    // function(error){
    //     return Promise.resolve(error)
    // }
    })

Vue.use(ElementUI)
Vue.use(axios)
Vue.use(Vuex)
Vue.use(vueEsign)
Vue.use(VideoPlayer)
Vue.use(AMap);
AMap.initAMapApiLoader({
    // 高德key
    key: '19bb10f7ec56d14e2b51be020134076c',   //自己的key
    // 插件集合 （插件按需引入）
    plugin: ['Geolocation']
  });
  







Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    components: {
        App
    },
    template: '<App/>'
})